from selenium.webdriver.common.by import By

from common.Utils import BolgDriver

class BlogPublish:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://8.137.19.140:9090/blog_edit.html"
        self.driver = BolgDriver.driver
        self.driver.get(self.url)
    def BlogPublishByLogin(self):
        # 填写博客标题，按“发布文章“按钮
        self.driver.find_element(By.CSS_SELECTOR,"#title").send_keys("aa")
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        # 如果博客列表的最下面的博客标题是”aa“，说明发布成功
        text=self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div:nth-child(30) > div.title").text
        assert text=="aa"
        # 截图
        BolgDriver.getScreenShot()

    def BlogPublishByNotLogin(self):
        self.driver.back()
        # 截图
        BolgDriver.getScreenShot()
        # 如果成功回到登录界面，那么找不到头像
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.left > div > img")